<template>
	<div class="f2bpm-page-layout">
		<div id="centerDiv" class="auto-window-height-select p10">
			<div  class="wfdialogHeaderToolBar">
				<a role="button" onclick="FUI.Window.closeEdit()" id="cancel" class="btn btn-default btn-sm mr2">
					<i class="fa fa-minus-circle"></i> 返回
				</a>
			</div>
			<f2bpm-datagrid ref="grid" grid="grid" height="full-80" :pager-config="tablePage" :data="tableData" :columns="tableColumn" @page-change="pageChange">
			</f2bpm-datagrid>
		</div>
		
	</div>
</template>

<script>
	export default {
		onLoad: function(option) {
			var that = this;
			var success = that.$store.getters.validateLogin;
			if (!success) {
				FUI.Window.showMsg("您未登录")
				return false;
			}
		},
		data() {
			return {
				treeFilterText: '',
				isCollapsed: false,
				wiid: '',
				tablePage: {
					pageCount: 0,
					sort: 'createdTime', //排序字段
					order: 'asc', //排序方向
					startIndex: 0,
					total: 0,
					currentPage: 1,
					pageSize: 100,
					align: 'center',
					pageSizes: [10, 20, 50, 100, 200, 500],
					layout: "total, sizes, prev, pager, next",
					perfect: true
				},
				loading: false,
				treeData: [],
				tableData: [],
				tableColumn: [{
						type: 'seq',
						width: 55,
						title: '序号',
						align: 'center'
					},
					{
						field: 'activityName',
						title: '传阅所在环节',
						width: 180,
						align: 'center'
					},
					{
						field: 'fromCreator',
						title: '传阅者',
						width: 120,
						align: 'center',
						formatter: function(rec, col, value) {
							return Object.toProcSecrecy(rec.fromCreator);
						}
					},
					{
						field: 'realName',
						title: '传阅到',
						width: 120,
						align: 'center',
						formatter: function(rec, col, value) {
							var depName = rec.userDpName == null ? "" : "(" + rec.userDpName + ")";
							return Object.toProcSecrecy(rec.realName) + depName;
						}
					},
					{
						field: 'createdTime',
						title: '传阅时间',
						width: 150,
						align: 'center',
						formatter: function(rec, col, value) {
							var value = rec.createdTime;
							if (value == '' || value == null) {
								return '';
							}
							return Object.toJsonDateTimeFormatter(value);
						}
					}, {
						field: 'completedTime',
						title: '审阅时间',
						width: 150,
						align: 'center',
						formatter: function(rec, col, value) {
							var value = rec.completedTime;
							if (value == '' || value == null) {
								return '';
							}
							return Object.toJsonDateTimeFormatter(value);
						}
					}, {
						field: 'taskState',
						title: '处理状态',
						width: 150,
						type: 'html',
						align: 'center',
						formatter: function(rec, col, value) {
							var text = taskStateFormatter(rec);
							return text;
						}
					},
					{
						field: 'opinion',
						title: '传阅留言',
						align: 'center',
						type: 'html',
						width: 250,
						formatter: function(rec, col, value) {
							if (value == null)
								value = "";
							var result = "";
							switch (rec.completedType) {
								case "Invalid":
									result = "<em>【流程作废】</em>";
									break;
								case "Activation":
									result = "<em>【流程重新激活】</em>";
									break;
								case "Reject":
									result = "<em>【驳回】</em>";
									break;
								case "Referred":
									result = "<em>【转办】</em>";
									break;
								case "TaskCommunication":
									result = "【沟通】";
									break;
							}

							if (rec.approAction) {
								result += "【" + rec.approAction + "】";
							}
							if (rec.activityName == "结束" && rec.completedType == "Approval") {
								return value;
							}
							return result + value;
						}
					}
				]
			};
		},
		created() {
			var that = this;
			that.wiid = Object.toQueryString("wiid");
			this.getGridData();
		},
		computed: {
			countGridHeight() {
				return $(document).height() - 10;
			}
		},
		methods: {
			//刷新列表
			refreshGrid(parentGridId, parm) {
				var that = this;
				that.dataGridSearch();
			},
			dataGridReSet() {
				let that = this;
				this.dataGridSearch();
			},
			dataGridSearch() {
				this.tablePage.currentPage = 1;
				this.tablePage.startIndex = 0;
				this.getGridData();
			},
			getGridData() {
				var that = this;
				var parm = {}
				parm.wiid = that.wiid;

				parm.page = that.tablePage.currentPage;
				parm.rows = that.tablePage.pageSize;
				parm.sort = that.tablePage.sort;
				parm.order = that.tablePage.order;
				var res = Object.toAjaxJson(FUI.Handlers.WorkflowBusinessHandler, 'loadCirculatedHistory', parm, true,
					null,
					function(res) {
						if (res.success) {
							that.tableData = res.rows;
							that.tablePage.total = res.total;
							that.tablePage.pageCount = res.pageCount;
						} else {
							FUI.Window.showMsg(that, res.msg);
						}
					});
			},
			pageChange({
				currentPage,
				pageSize
			}) {
				this.tablePage.currentPage = currentPage;
				this.tablePage.pageSize = pageSize;
				this.tablePage.startIndex = (currentPage - 1) * pageSize;
				this.getGridData();
			}

		},
		mounted() {
			window.myvm = this;
		}
	}
</script>
